/*
 *    Copyright (c) 2018-2025, cloud All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: cloud
 */

package com.fuyao.cloud.admin.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fuyao.cloud.admin.api.dto.SysNumberDTO;
import com.fuyao.cloud.admin.api.entity.SysServerNumber;
import com.fuyao.cloud.common.core.util.R;
import com.fuyao.cloud.common.log.annotation.SysLog;
import com.fuyao.cloud.admin.service.SysServerNumberService;
import com.fuyao.cloud.common.security.annotation.Inner;
import org.springframework.security.access.prepost.PreAuthorize;
import com.fuyao.cloud.common.excel.annotation.ResponseExcel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 扶摇编码生成类
 *
 * @author liyue
 * @date 2021-11-15 09:56:07
		*/
@RestController
@RequiredArgsConstructor
@RequestMapping("/sysservernumber")
@Api(value = "sysservernumber", tags = "扶摇编码生成类管理")
public class SysServerNumberController {

	private final SysServerNumberService sysServerNumberService;

	/**
	 * 分页查询
	 *
	 * @param page            分页对象
	 * @param sysServerNumber 扶摇编码生成类
	 * @return
	 */
	@ApiOperation(value = "分页查询", notes = "分页查询")
	@GetMapping("/page")
	@PreAuthorize("@pms.hasPermission('admin_sysservernumber_view')")
	public R getSysServerNumberPage(Page page, SysServerNumber sysServerNumber) {
		return R.ok(sysServerNumberService.page(page, Wrappers.query(sysServerNumber)));
	}


	/**
	 * 通过id查询扶摇编码生成类
	 *
	 * @param id id
	 * @return R
	 */
	@ApiOperation(value = "通过id查询", notes = "通过id查询")
	@GetMapping("/{id}")
	@PreAuthorize("@pms.hasPermission('admin_sysservernumber_view')")
	public R getById(@PathVariable("id") Long id) {
		return R.ok(sysServerNumberService.getById(id));
	}

	/**
	 * 新增扶摇编码生成类
	 *
	 * @param sysServerNumber 扶摇编码生成类
	 * @return R
	 */
	@ApiOperation(value = "新增扶摇编码生成类", notes = "新增扶摇编码生成类")
	@SysLog("新增扶摇编码生成类")
	@PostMapping
	@PreAuthorize("@pms.hasPermission('admin_sysservernumber_add')")
	public R save(@RequestBody SysServerNumber sysServerNumber) {
		return R.ok(sysServerNumberService.save(sysServerNumber));
	}

	/**
	 * 修改扶摇编码生成类
	 *
	 * @param sysServerNumber 扶摇编码生成类
	 * @return R
	 */
	@ApiOperation(value = "修改扶摇编码生成类", notes = "修改扶摇编码生成类")
	@SysLog("修改扶摇编码生成类")
	@PutMapping
	@PreAuthorize("@pms.hasPermission('admin_sysservernumber_edit')")
	public R updateById(@RequestBody SysServerNumber sysServerNumber) {
		return R.ok(sysServerNumberService.updateById(sysServerNumber));
	}

	/**
	 * 通过id删除扶摇编码生成类
	 *
	 * @param id id
	 * @return R
	 */
	@ApiOperation(value = "通过id删除扶摇编码生成类", notes = "通过id删除扶摇编码生成类")
	@SysLog("通过id删除扶摇编码生成类")
	@DeleteMapping("/{id}")
	@PreAuthorize("@pms.hasPermission('admin_sysservernumber_del')")
	public R removeById(@PathVariable Long id) {
		return R.ok(sysServerNumberService.removeById(id));
	}


	/**
	 * 导出excel 表格
	 *
	 * @param sysServerNumber 查询条件
	 * @return excel 文件流
	 */
	@ResponseExcel
	@GetMapping("/export")
	@PreAuthorize("@pms.hasPermission('admin_sysservernumber_export')")
	public List<SysServerNumber> export(SysServerNumber sysServerNumber) {
		return sysServerNumberService.list(Wrappers.query(sysServerNumber));
	}

	@ApiOperation(value = "查询编码数值", notes = "查询编码数值")
	@PostMapping("/getNumberValue")
	public R getNumberValue(@RequestBody SysNumberDTO sysNumberDTO) {
		return R.ok(sysServerNumberService.getServerNumber(sysNumberDTO));
	}

	@ApiOperation(value = "根据传入编码+格式化数值位数生成编码", notes = "根据传入父级编码+编码+格式化数值位数生成编码")
	@PostMapping("/getNumberStr")
	public R getNumberStr(@RequestBody SysNumberDTO sysNumberDTO) {
		return R.ok(sysServerNumberService.getServerNumberStr(sysNumberDTO));
	}

	@ApiOperation(value = "根据传入父级编码+编码+格式化数值位数生成编码", notes = "根据传入父级编码+编码+格式化数值位数生成编码")
	@PostMapping("/getNumberParentJoinCoeStr")
	public R getServerNumberJoinParent(@RequestBody SysNumberDTO sysNumberDTO) {
		return R.ok(sysServerNumberService.getServerNumberJoinParent(sysNumberDTO));
	}

	@ApiOperation(value = "根据传入编码+格式化数值位数生成编码", notes = "格式化数值位数生成编码")
	@PostMapping("/getNumberMap")
	public R getNumberMap(@RequestBody SysNumberDTO sysNumberDTO) {
		return R.ok(sysServerNumberService.getNumberMap(sysNumberDTO));
	}

}
